<template>
	<view>
		<view class="info" v-show="coupon">
			<view class="flex-row justify-between align-center">
				<view>产品名称</view>
				<view class="black">{{send.coupon_name}}</view>
			</view>
			<view class="flex-row justify-between align-center">
				<view>有效期</view>
				<view class="black">{{coupon.expire_at}}</view>
			</view>
			<view class="flex-row justify-between align-center">
				<view>价格</view>
				<view class="active">{{coupon.sell_price}}</view>
			</view>
			<view class="flex-row justify-between align-center">
				<view>订单信息</view>
				<view class="black">{{send.desc}}</view>
			</view>
		</view>

		<my-btn gold style="margin: 60rpx auto" @click="getOrder">立即购买</my-btn>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				coupon: '',
				send: '',
			};
		},
		onLoad(opt) {
			this.id = opt.id
			this.getData()
		},
		methods: {
			getData() {
				this.$u.get('/coupons/sale/info?id=' + this.id).then(res => {
					this.coupon = res.data.result.coupon
					this.send = res.data.result.coupon.send
				})
			},
			getOrder() {
				this.$u.post('/coupons/sale/seckill?sell_id=' + this.id).then(res => {
					if (res.data.code == 0) {
						let trade_no = res.data.result.trade_no
						uni.showLoading({
							mask: true,
							title: '订单创建中...'
						})

						setTimeout(() => {
							this.$goto('/pages/coupon/pay?no=' + trade_no)
						}, 2000)
					} else {
						this.$msg(res.data.msg)
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.info {
		padding: 36rpx;
		font-size: 24rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #999999;
		background: #fff;

		.active {
			color: #FF8B56;
		}

		.black {
			color: black;
		}

		.flex-row {
			height: 80rpx;
			border-bottom: 1rpx solid rgba(0, 0, 0, 0.03);
		}
	}

	.item {
		height: 100rpx;
		display: flex;
		align-items: center;

		&.on {
			opacity: 0.7;
			transform: translate(1px, 1px);
		}

		&.bt {
			justify-content: space-between;
		}

		.text {
			min-width: 160rpx;
		}

		.radio {
			width: 40rpx;
			height: 40rpx;
			margin-right: 24rpx;
			background: url(../../static/images/ra0.png);
			background-size: 100% 100%;

			&.on {
				background: url(../../static/images/ra1.png);
				background-size: 100% 100%;
			}
		}
	}

	.pay-pop {
		.money {
			font-size: 20rpx;
			color: #ff9900;
			position: relative;
			padding: 20rpx;
			text-align: center;

			.lg {
				font-size: 80rpx;
			}

			.close {
				position: absolute;
				padding: 10rpx;
				top: 20rpx;
				right: 20rpx;
				line-height: 28rpx;
				font-size: 28rpx;
			}
		}

		.ipt {
			display: flex;
			justify-content: center;
		}

		.tips {
			padding: 10rpx 0;
			text-align: center;
			color: #909399;
		}
	}
</style>
